package org.linlinjava.litemall.admin.vo;

import org.apache.commons.lang3.StringUtils;
import org.linlinjava.litemall.core.util.bcrypt.BCryptPasswordEncoder;
import org.linlinjava.litemall.db.domain.Vendor;
import org.linlinjava.litemall.db.domain.VendorEmployee;

public class VendorRegVo {
    private String username;
    private String name;
    private String password;
    private String phone;

    private String vendorName;
    private String countryCode;
    private String provinceCode;
    private String cityCode;
    private String regionCode;
    private String addr;
    private String legalPerson;
    private String tel;

    public Vendor toVendor() {
        Vendor vendor = new Vendor();
        vendor.setVendorCode(null);
        vendor.setVendorName(getVendorName());
        vendor.setCountryCode(countryCode);
        vendor.setProvinceCode(provinceCode);
        vendor.setCityCode(cityCode);
        vendor.setRegionCode(regionCode);
        vendor.setAddr(getAddr());
        vendor.setTel(getTel());
        vendor.setLegalPerson(getLegalPerson());
        vendor.setStatus(-1);
        return vendor;
    }
    public VendorEmployee toVendorEmployee(int vendorId) {
        VendorEmployee emp = new VendorEmployee();

        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String encodedPassword = encoder.encode(password);
        emp.setPassword(encodedPassword);

        emp.setVendorId(vendorId);
        emp.setUsername(username);
        emp.setName(name);
        emp.setPhone(phone);
        return emp;
    }

    public boolean isValid() {
        if (StringUtils.isAnyBlank(username, name, password, phone, vendorName, addr, legalPerson, tel)) {
            return false;
        }
        return true;
    }
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getVendorName() {
        return vendorName;
    }

    public void setVendorName(String vendorName) {
        this.vendorName = vendorName;
    }

    public String getProvinceCode() {
        return provinceCode;
    }

    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }

    public String getCityCode() {
        return cityCode;
    }

    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }

    public String getRegionCode() {
        return regionCode;
    }

    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getLegalPerson() {
        return legalPerson;
    }

    public void setLegalPerson(String legalPerson) {
        this.legalPerson = legalPerson;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

}
